unit wbSha256;

interface

uses SysUtils, DCPsha256;

type
  THashBytes = array [0 .. 31] of byte;

  TwbSha256 = class(TDCP_sha256)
    function BytesToStr(hb: THashBytes): AnsiString;
    function HashBytes(str: AnsiString; id: integer): THashBytes;
  end;

implementation

function TwbSha256.BytesToStr(hb: THashBytes): AnsiString;
var
  s: AnsiString;
  j: integer;
begin
  s := '';
  for j := 0 to Length(hb) - 1 do // convert it into a hex string
    s := s + IntToHex(hb[j], 2);
  result := s;
end;

function TwbSha256.HashBytes(str: AnsiString; id: integer): THashBytes;
var
  HashDigest: THashBytes;
  salt: array [0 .. 1] of byte;
begin
  salt[0] := hi(id);
  salt[1] := lo(id);
  Init;
  Update(salt, sizeOf(salt));
  UpdateStr(str);
  Final(HashDigest);
  result := HashDigest;
end;




end.
